home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / copy_reg.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  5KB  |  187 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Helper to provide extensibility for pickle/cPickle.
  5.  
  6. This is only useful to add pickle support for extension types defined in
  7. C, not for instances of user-defined classes.
  8. '''
  9. from types import ClassType as _ClassType
  10. __all__ = [
  11.     'pickle',
  12.     'constructor',
  13.     'add_extension',
  14.     'remove_extension',
  15.     'clear_extension_cache']
  16. dispatch_table = { }
  17.  
  18. def pickle(ob_type, pickle_function, constructor_ob = None):
  19.     if type(ob_type) is _ClassType:
  20.         raise TypeError('copy_reg is not intended for use with classes')
  21.     type(ob_type) is _ClassType
  22.     if not hasattr(pickle_function, '__call__'):
  23.         raise TypeError('reduction functions must be callable')
  24.     hasattr(pickle_function, '__call__')
  25.     dispatch_table[ob_type] = pickle_function
  26.     if constructor_ob is not None:
  27.         constructor(constructor_ob)
  28.     
  29.  
  30.  
  31. def constructor(object):
  32.     if not hasattr(object, '__call__'):
  33.         raise TypeError('constructors must be callable')
  34.     hasattr(object, '__call__')
  35.  
  36.  
  37. try:
  38.     complex
  39. except NameError:
  40.     pass
  41.  
  42.  
  43. def pickle_complex(c):
  44.     return (complex, (c.real, c.imag))
  45.  
  46. pickle(complex, pickle_complex, complex)
  47.  
  48. def _reconstructor(cls, base, state):
  49.     if base is object:
  50.         obj = object.__new__(cls)
  51.     else:
  52.         obj = base.__new__(cls, state)
  53.         if base.__init__ != object.__init__:
  54.             base.__init__(obj, state)
  55.         
  56.     return obj
  57.  
  58. _HEAPTYPE = 512
  59.  
  60. def _reduce_ex(self, proto):
  61.     if not proto < 2:
  62.         raise AssertionError
  63.     for base in self.__class__.__mro__:
  64.         if hasattr(base, '__flags__') and not (base.__flags__ & _HEAPTYPE):
  65.             break
  66.             continue
  67.         proto < 2
  68.     else:
  69.         base = object
  70.     if base is object:
  71.         state = None
  72.     elif base is self.__class__:
  73.         raise TypeError, "can't pickle %s objects" % base.__name__
  74.     
  75.     state = base(self)
  76.     args = (self.__class__, base, state)
  77.     
  78.     try:
  79.         getstate = self.__getstate__
  80.     except AttributeError:
  81.         if getattr(self, '__slots__', None):
  82.             raise TypeError('a class that defines __slots__ without defining __getstate__ cannot be pickled')
  83.         getattr(self, '__slots__', None)
  84.         
  85.         try:
  86.             dict = self.__dict__
  87.         except AttributeError:
  88.             dict = None
  89.         except:
  90.             None<EXCEPTION MATCH>AttributeError
  91.         
  92.  
  93.         None<EXCEPTION MATCH>AttributeError
  94.  
  95.     dict = getstate()
  96.     if dict:
  97.         return (_reconstructor, args, dict)
  98.     return (_reconstructor, args)
  99.  
  100.  
  101. def __newobj__(cls, *args):
  102.     return cls.__new__(cls, *args)
  103.  
  104.  
  105. def _slotnames(cls):
  106.     """Return a list of slot names for a given class.
  107.  
  108.     This needs to find slots defined by the class and its bases, so we
  109.     can't simply return the __slots__ attribute.  We must walk down
  110.     the Method Resolution Order and concatenate the __slots__ of each
  111.     class found there.  (This assumes classes don't modify their
  112.     __slots__ attribute to misrepresent their slots after the class is
  113.     defined.)
  114.     """
  115.     names = cls.__dict__.get('__slotnames__')
  116.     if names is not None:
  117.         return names
  118.     names = []
  119.     if not hasattr(cls, '__slots__'):
  120.         pass
  121.     else:
  122.         for c in cls.__mro__:
  123.             if '__slots__' in c.__dict__:
  124.                 slots = c.__dict__['__slots__']
  125.                 if isinstance(slots, basestring):
  126.                     slots = (slots,)
  127.                 
  128.                 for name in slots:
  129.                     if name in ('__dict__', '__weakref__'):
  130.                         continue
  131.                         continue
  132.                     if name.startswith('__') and not name.endswith('__'):
  133.                         names.append('_%s%s' % (c.__name__, name))
  134.                         continue
  135.                     names.append(name)
  136.                 
  137.         
  138.     
  139.     try:
  140.         cls.__slotnames__ = names
  141.     except:
  142.         pass
  143.  
  144.     return names
  145.  
  146. _extension_registry = { }
  147. _inverted_registry = { }
  148. _extension_cache = { }
  149.  
  150. def add_extension(module, name, code):
  151.     '''Register an extension code.'''
  152.     code = int(code)
  153.     if code <= code:
  154.         pass
  155.     elif not code <= 2147483647:
  156.         raise ValueError, 'code out of range'
  157.     
  158.     key = (module, name)
  159.     if _extension_registry.get(key) == code and _inverted_registry.get(code) == key:
  160.         return None
  161.     if key in _extension_registry:
  162.         raise ValueError('key %s is already registered with code %s' % (key, _extension_registry[key]))
  163.     key in _extension_registry
  164.     if code in _inverted_registry:
  165.         raise ValueError('code %s is already in use for key %s' % (code, _inverted_registry[code]))
  166.     code in _inverted_registry
  167.     _extension_registry[key] = code
  168.     _inverted_registry[code] = key
  169.  
  170.  
  171. def remove_extension(module, name, code):
  172.     '''Unregister an extension code.  For testing only.'''
  173.     key = (module, name)
  174.     if _extension_registry.get(key) != code or _inverted_registry.get(code) != key:
  175.         raise ValueError('key %s is not registered with code %s' % (key, code))
  176.     _inverted_registry.get(code) != key
  177.     del _extension_registry[key]
  178.     del _inverted_registry[code]
  179.     if code in _extension_cache:
  180.         del _extension_cache[code]
  181.     
  182.  
  183.  
  184. def clear_extension_cache():
  185.     _extension_cache.clear()
  186.  
  187.